{extend name="base" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-form">
            <div class="layui-form-item">
                <form action="{:url('user/finance/report')}" class="layui-form" method="get">
                <div class="layui-inline">
                    <label class="layui-form-label">时间范围</label>
                    <div class="layui-input-inline">
                        <input type="text" name="dateframe" class="layui-input" id="test16" value="{$dateframe}" autocomplete="off" >
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i> 查看数据</button>
                </div>
                </form>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md4">
                <table class="layui-table layui-form" lay-filter="demo">
                    <thead>
                        <tr>
                            <th>部门</th>
                            <th>收入</th>
                            <th>支出</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach name="department" item="r"}
                        <tr>
                            <td>{$r.name}</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1,'department'=>$r.id])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2,'department'=>$r.id])->sum('price'),2)}元</td>
                        </tr>
                        {/foreach}
                    </tbody>
                    <footer>
                        <tr style="background-color:#e2e2e2;font-weight: bold">
                            <td>合计</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2])->sum('price'),2)}元</td>
                        </tr>
                    </footer>
                </table>
            </div>
            <div class="layui-col-md4">
                <table class="layui-table layui-form" lay-filter="demo">
                    <thead>
                        <tr>
                            <th>类目</th>
                            <th>收入</th>
                            <th>支出</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach name="category" item="r"}
                        <tr>
                            <td>{$r.name}</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1,'category'=>$r.id])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2,'category'=>$r.id])->sum('price'),2)}元</td>
                        </tr>
                        {/foreach}
                    </tbody>
                    <footer>
                        <tr style="background-color:#e2e2e2;font-weight: bold">
                            <td>合计</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2])->sum('price'),2)}元</td>
                        </tr>
                    </footer>
                </table>
            </div>
            <div class="layui-col-md4">
                <table class="layui-table layui-form" lay-filter="demo">
                    <thead>
                        <tr>
                            <th>报销人</th>
                            <th>收入</th>
                            <th>支出</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach name="user" item="r"}
                        <tr>
                            <td>{$r.realname}</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1,'bxuser'=>$r.id])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2,'bxuser'=>$r.id])->sum('price'),2)}元</td>
                        </tr>
                        {/foreach}
                    </tbody>
                    <footer>
                        <tr style="background-color:#e2e2e2;font-weight: bold">
                            <td>合计</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>1])->sum('price'),2)}元</td>
                            <td>￥{:number_format(model('finance')->where($where)->where(['type'=>2])->sum('price'),2)}元</td>
                        </tr>
                    </footer>
                </table>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
  laydate.render({
        elem: '#test16'
        ,range: '-'
  });
</script>
{/block}